/**
 * 
 * @param {*} ref 传入组件的ref值，
 */
export default function (ref) {
    return {
        mounted() {
            this.$bus.$on('setMainScroll', this.handleSetMainScroll);
            this.$refs[ref].addEventListener("scroll", this.handleMainScroll);
        },
        beforeDestroy() {
            this.$bus.$off('setMainScroll',this.handleSetMainScroll);
            //通知其他组件该组件已经被销毁了，ref已经没有了
            this.$bus.$emit('mainScroll');
            this.$refs[ref].removeEventListener("scroll", this.handleMainScroll);
          },
        methods: {
            handleMainScroll() {
                this.$bus.$emit("mainScroll", this.$refs[ref]);
            },
            handleSetMainScroll(scrollTop) {
                this.$refs[ref].scrollTop = scrollTop;
            }
        }

    }
}